package com.spareparts.activity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
import cm.framework.net.ClientSession;
import cm.framework.net.ControlRunnable;
import cm.framework.net.IErrorListener;
import cm.framework.net.IResponseListener;
import cm.framework.protocol.BaseHttpRequest;
import cm.framework.protocol.BaseHttpResponse;
import cm.framework.protocol.ErrorResponse;

import com.spareparts.R;
import com.spareparts.activity.base.BaseActivity;
import com.spareparts.entyties.JuDian;
import com.spareparts.entyties.QuYu;
import com.spareparts.entyties.WareHouse;
import com.spareparts.entyties.WuLiao;
import com.spareparts.protocol.JuDianRequest;
import com.spareparts.protocol.JuDianResponse;
import com.spareparts.protocol.QuYuRequest;
import com.spareparts.protocol.QuYuResponse;
import com.spareparts.protocol.SearchRequest;
import com.spareparts.protocol.SearchResponse;
import com.spareparts.protocol.WarehouseByQuYuRequest;
import com.spareparts.protocol.WarehouseByQuYuResponse;
import com.spareparts.protocol.WarehouseResponse;
import com.spareparts.protocol.WuLiaoRequest;
import com.spareparts.protocol.WuLiaoResponse;

public class SearchActivity extends BaseActivity {
	/**
	 * 查询按钮
	 */
	private Button mSearch;
	private Button mReset;
	private Spinner mSpinnerQuYu;
	private Spinner mSpinnerJuDian;
	private Spinner mSpinnerKuFang;
//	private Spinner mSpinnerWuLiao;
	private TextView mTextViewResult;
	private TextView mTextViewJuZhan;
	private TextView mTextViewKuFang;
	private TextView mTextViewTotle;
	/**
	 * 物料编码
	 */
	private TextView mTextViewWuliaoBianMa;

	private ListView listview;

	private List<QuYu> mListQuYu;
	private List<WareHouse> mListWareHouse;
	private List<JuDian> mListJuDian;
	private List<WuLiao> mListWuLiao;
	private List<WuLiao> mListWuLiaoSearch = new ArrayList<WuLiao>();
	private SearchAdapter searchAdapter = new SearchAdapter();
	private SpinnerAdapter mAdapterQuYu;
	private SearchResponse searchResponse;
	
	private EditText mEditTextWuliao;
	/**
	 * 上一页按钮
	 */
	private Button bt_page_pre;
	/**
	 * 分页信息
	 */
	private TextView tv_page_info;
	/**
	 * 下一页按钮
	 */
	private Button bt_page_next;
	/**
	 * 跳页输入
	 */
	private EditText et_page_jump;
	/**
	 * 跳页按钮
	 */
	private Button bt_page_jump;
	/**
	 * 查询条件
	 */
	String quyuStr ;
	/**
	 * 查询条件
	 */
	String judianStr ;
	/**
	 * 查询条件
	 */
	String kufangStr ;
	/**
	 * 查询条件
	 */
	String wuliaoStr ;
	/**
	 * 当前页
	 */
	private int currentPageNum = 1;
	/**
	 * 当搜索结果条目点击时候，监听器
	 */
	private SearchListItemClickListener searchListItemClickListener = new SearchListItemClickListener();
	/**
	 * 详细点击，监听
	 */
	private WuLiaoDetailListener wuLiaoDetailListener = new WuLiaoDetailListener();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search);
		//查询按钮
		mSearch = (Button) findViewById(R.id.ButtonSearch);
		mReset = (Button) findViewById(R.id.ButtonReset);
		mSpinnerQuYu = (Spinner) findViewById(R.id.spinner_quyu);
		mSpinnerJuDian = (Spinner) findViewById(R.id.spinner_judian);
		mSpinnerKuFang = (Spinner) findViewById(R.id.spinner_kufang);
//		mSpinnerWuLiao = (Spinner) findViewById(R.id.spinner_wuliao);
		mEditTextWuliao = (EditText) findViewById(R.id.editText_wuliao);
		mTextViewResult = (TextView) findViewById(R.id.TextView_Result);
		mTextViewJuZhan = (TextView) findViewById(R.id.TextView_JuZhan);
		mTextViewKuFang = (TextView) findViewById(R.id.TextView_KuFang);
		mTextViewWuliaoBianMa = (TextView) findViewById(R.id.TextView_WuliaoBianMa);
		mTextViewTotle = (TextView) findViewById(R.id.TextView_Totle);
		//上一页按钮
		bt_page_pre = (Button) findViewById(R.id.bt_page_pre);
		//分页信息
		tv_page_info = (TextView) findViewById(R.id.tv_page_info);
		//下一页按钮
		bt_page_next = (Button) findViewById(R.id.bt_page_next);
		//跳页输入
		et_page_jump = (EditText) findViewById(R.id.et_page_jump);
		//跳页按钮
		bt_page_jump = (Button) findViewById(R.id.bt_page_jump);
		listview = (ListView) findViewById(R.id.listview);
		listview.setAdapter(searchAdapter);
		//item点击监听器
		listview.setOnItemClickListener(searchListItemClickListener);
		getQuYu(false);
		getWuLiao();
		//查询按钮点击事件
		mSearch.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				//执行搜索
				doSearch(true);
			}
		});

		mReset.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				getQuYu(true);
				getWuLiao();
			}
		});
		bt_page_pre.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				doJumpPage((currentPageNum-1)+"");
			}
		});
		bt_page_next.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				doJumpPage((currentPageNum+1)+"");
			}
		});
		bt_page_jump.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				doJumpPage(et_page_jump.getText().toString());
			}
		});
	}

	/**
	 * 查询网络
	 */
	private void doSearch(boolean isReset) {
		quyuStr = getSpinnerString(mSpinnerQuYu);
		judianStr = getSpinnerString(mSpinnerJuDian);
		kufangStr = getSpinnerString(mSpinnerKuFang);
		wuliaoStr = mEditTextWuliao.getText() == null ? "" : mEditTextWuliao.getText().toString();
		// TODO 验证数据合法性
		currentPageNum = 1;
		doSearchForInternet(currentPageNum+"");
	}
	/**
	 * 翻页
	 */
	private void doJumpPage(String pageNum) {
		String errorMessage = "";
		try{
			int toPageNum = Integer.parseInt(pageNum);
			do{
				if(toPageNum<1){
					errorMessage = "不得小于第一页";
					break;
				}
				if(toPageNum>(searchResponse.searchResponseModel.temp.count%10==0?searchResponse.searchResponseModel.temp.count/10:searchResponse.searchResponseModel.temp.count/10+1)){
					errorMessage = "不得大于最后一页";
					break;
				}
				currentPageNum = toPageNum;
				doSearchForInternet(currentPageNum-1+"");
			}while(false);
		}catch (NumberFormatException e2) {
			errorMessage = "跳转页数 '"+pageNum+"' 格式不正确";
		}catch(Exception e){
			errorMessage = "查询失败";
		}
		if(!TextUtils.isDigitsOnly(errorMessage)){
			Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show();
		}
	}
	private void doSearchForInternet(String pageNum) {
		//请求网络
		ClientSession.getInstance().setDefErrorReceiver(mStateAlert);
		ClientSession.getInstance().setDefStateReceiver(mStateAlert);
		ClientSession.getInstance().asynGetResponse(
				new SearchRequest(mCommonApplication.mUserInfo.userId,quyuStr, judianStr, kufangStr, wuliaoStr, pageNum),
				new IResponseListener() {
					@Override
					public void onResponse(BaseHttpResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						/*
						 * numbersid 物料编码
						 * number 件
						 * numberwid 库房 
						 * count 记录
						 * numberrid 区域
						 */
						searchResponse = (SearchResponse) arg0;
						mHandler.sendEmptyMessage(5);
					}
				}, new IErrorListener() {
					@Override
					public void onError(ErrorResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						if (null != arg0 && null != arg0.getErrorDesc()
								&& !arg0.getErrorDesc().trim().equals("")) {
							Message msg = new Message();
							msg.what = 20;
							msg.obj = arg0.getErrorDesc();
							mHandler.sendMessage(msg);
						}
					}
				});
	}
	private void getQuYu(boolean isReset) {
		if (isReset) {
			ClientSession.getInstance().setDefErrorReceiver(null);
			ClientSession.getInstance().setDefStateReceiver(null);
		} else {
			ClientSession.getInstance().setDefErrorReceiver(mStateAlert);
			ClientSession.getInstance().setDefStateReceiver(mStateAlert);
		}
		ClientSession.getInstance().asynGetResponse(
				new QuYuRequest(mCommonApplication.mUserInfo.userId),
				new IResponseListener() {
					@Override
					public void onResponse(BaseHttpResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						QuYuResponse quYuResponse = (QuYuResponse) arg0;
						mListQuYu = quYuResponse.mQuYu;
						mHandler.sendEmptyMessage(1);
					}
				}, new IErrorListener() {
					@Override
					public void onError(ErrorResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						if (null != arg0 && null != arg0.getErrorDesc()
								&& !arg0.getErrorDesc().trim().equals("")) {
							Message msg = new Message();
							msg.what = 20;
							msg.obj = arg0.getErrorDesc();
							mHandler.sendMessage(msg);
						}
					}
				});
	}

	private void getWarehouse(String quyu) {
		ClientSession.getInstance().setDefErrorReceiver(null);
		ClientSession.getInstance().setDefStateReceiver(null);
		ClientSession.getInstance().asynGetResponse(
				new WarehouseByQuYuRequest(mCommonApplication.mUserInfo.userId,
						quyu), new IResponseListener() {
					@Override
					public void onResponse(BaseHttpResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						WarehouseByQuYuResponse warehouseByQuYuResponse = (WarehouseByQuYuResponse) arg0;
						mListWareHouse = warehouseByQuYuResponse.mWareHouseList;
						mHandler.sendEmptyMessage(2);
					}
				}, new IErrorListener() {
					@Override
					public void onError(ErrorResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						if (null != arg0 && null != arg0.getErrorDesc()
								&& !arg0.getErrorDesc().trim().equals("")) {
							Message msg = new Message();
							msg.what = 20;
							msg.obj = arg0.getErrorDesc();
							mHandler.sendMessage(msg);
						}
					}
				});
	}

	private void getJuDian(String cangku) {
		ClientSession.getInstance().setDefErrorReceiver(null);
		ClientSession.getInstance().setDefStateReceiver(null);
		ClientSession.getInstance().asynGetResponse(
				new JuDianRequest(mCommonApplication.mUserInfo.userId, cangku),
				new IResponseListener() {
					@Override
					public void onResponse(BaseHttpResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						JuDianResponse juDianResponse = (JuDianResponse) arg0;
						mListJuDian = juDianResponse.mJuDian;
						mHandler.sendEmptyMessage(3);
					}
				}, new IErrorListener() {
					@Override
					public void onError(ErrorResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						if (null != arg0 && null != arg0.getErrorDesc()
								&& !arg0.getErrorDesc().trim().equals("")) {
							Message msg = new Message();
							msg.what = 20;
							msg.obj = arg0.getErrorDesc();
							mHandler.sendMessage(msg);
						}
					}
				});
	}

	private void getWuLiao() {
		ClientSession.getInstance().setDefErrorReceiver(null);
		ClientSession.getInstance().setDefStateReceiver(null);
		ClientSession.getInstance().asynGetResponse(
				new WuLiaoRequest(mCommonApplication.mUserInfo.userId),
				new IResponseListener() {
					@Override
					public void onResponse(BaseHttpResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						WuLiaoResponse wuLiaoResponse = (WuLiaoResponse) arg0;
						mListWuLiao = wuLiaoResponse.mWuLiao;
						mHandler.sendEmptyMessage(4);
					}
				}, new IErrorListener() {
					@Override
					public void onError(ErrorResponse arg0,
							BaseHttpRequest arg1, ControlRunnable arg2) {
						if (null != arg0 && null != arg0.getErrorDesc()
								&& !arg0.getErrorDesc().trim().equals("")) {
							Message msg = new Message();
							msg.what = 20;
							msg.obj = arg0.getErrorDesc();
							mHandler.sendMessage(msg);
						}
					}
				});
	}

	@SuppressLint("HandlerLeak")
	private Handler mHandler = new Handler() {
		@Override
		public void dispatchMessage(Message msg) {
			super.dispatchMessage(msg);
			switch (msg.what) {
			case 1:
				// 设置区域spinner
				setSpinnerQuYu();
				break;
			case 2:
				// 设置仓库
				setSpinnerCangku();
			case 3:
				// 设置局点
				setSpinnerJuDian();
			case 4:
				// 设置物料
				setSpinnerWuLiao();
				break;
			case 5:
				// 搜索结果
				showSearchList();
			}
		}
	};

	/**
	 * 设置QuYuSpinner
	 */
	private void setSpinnerQuYu() {
		if (null != mListQuYu && mListQuYu.size() > 0) {
			final String[] strAdaptor = new String[mListQuYu.size()];
			for (int i = 0; i < mListQuYu.size(); i++) {
				QuYu oQuYu = mListQuYu.get(i);
				strAdaptor[i] = oQuYu.name;
			}
			SpinnerAdapter adaptor = new BaseAdapter() {

				@Override
				public int getCount() {
					return strAdaptor.length;
				}

				@Override
				public Object getItem(int position) {
					return strAdaptor[position];
				}

				@Override
				public long getItemId(int position) {
					return position;
				}

				@Override
				public View getView(int position, View convertView,
						ViewGroup parent) {
					TextView tv = new TextView(mContext);
					tv.setText(getItem(position).toString());
					tv.setTextSize(16);
					return tv;
				}

			};
			mSpinnerQuYu.setAdapter(adaptor);

			mSpinnerQuYu
					.setOnItemSelectedListener(new OnItemSelectedListener() {

						@Override
						public void onItemSelected(AdapterView<?> arg0,
								View arg1, int arg2, long arg3) {
							getWarehouse(mListQuYu.get(arg2).name);
						}

						@Override
						public void onNothingSelected(AdapterView<?> arg0) {

						}

					});
		}
	}

	/**
	 * 设置cangkuSpinner
	 */
	private void setSpinnerCangku() {
		if (null != mListWareHouse && mListWareHouse.size() > 0) {
			final String[] strAdaptor = new String[mListWareHouse.size()];
			for (int i = 0; i < mListWareHouse.size(); i++) {
				WareHouse oWareHouse = mListWareHouse.get(i);
				strAdaptor[i] = oWareHouse.wName;
			}
			SpinnerAdapter adaptor = new BaseAdapter() {

				@Override
				public int getCount() {
					return strAdaptor.length;
				}

				@Override
				public Object getItem(int position) {
					return strAdaptor[position];
				}

				@Override
				public long getItemId(int position) {
					return position;
				}

				@Override
				public View getView(int position, View convertView,
						ViewGroup parent) {
					TextView tv = new TextView(mContext);
					tv.setText(getItem(position).toString());
					tv.setTextSize(16);
					return tv;
				}

			};
			mSpinnerKuFang.setAdapter(adaptor);

			mSpinnerKuFang
					.setOnItemSelectedListener(new OnItemSelectedListener() {

						@Override
						public void onItemSelected(AdapterView<?> arg0,
								View arg1, int arg2, long arg3) {
							getJuDian(mListWareHouse.get(arg2).wName);
						}

						@Override
						public void onNothingSelected(AdapterView<?> arg0) {

						}

					});
		}
	}

	/**
	 * 设置JuDianSpinner
	 */
	private void setSpinnerJuDian() {
		if (null != mListJuDian && mListJuDian.size() > 0) {
			final String[] strAdaptor = new String[mListJuDian.size()];
			for (int i = 0; i < mListJuDian.size(); i++) {
				JuDian oJuDian = mListJuDian.get(i);
				strAdaptor[i] = oJuDian.pointName;
			}
			SpinnerAdapter adaptor = new BaseAdapter() {
				@Override
				public int getCount() {
					return strAdaptor.length;
				}

				@Override
				public Object getItem(int position) {
					return strAdaptor[position];
				}

				@Override
				public long getItemId(int position) {
					return position;
				}

				@Override
				public View getView(int position, View convertView,
						ViewGroup parent) {
					TextView tv = new TextView(mContext);
					tv.setText(getItem(position).toString());
					tv.setTextSize(16);
					return tv;
				}

			};
			mSpinnerJuDian.setAdapter(adaptor);

			mSpinnerJuDian
					.setOnItemSelectedListener(new OnItemSelectedListener() {

						@Override
						public void onItemSelected(AdapterView<?> arg0,
								View arg1, int arg2, long arg3) {

						}

						@Override
						public void onNothingSelected(AdapterView<?> arg0) {

						}

					});
		}
	}

	/**
	 * 设置JuDianSpinner
	 */
	private void setSpinnerWuLiao() {
		if (null != mListWuLiao && mListWuLiao.size() > 0) {
			final String[] strAdaptor = new String[mListWuLiao.size()];
			for (int i = 0; i < mListWuLiao.size(); i++) {
				WuLiao oWuLiao = mListWuLiao.get(i);
				strAdaptor[i] = oWuLiao.code;
			}
			SpinnerAdapter adaptor = new BaseAdapter() {
				@Override
				public int getCount() {
					return strAdaptor.length;
				}

				@Override
				public Object getItem(int position) {
					return strAdaptor[position];
				}

				@Override
				public long getItemId(int position) {
					return position;
				}

				@Override
				public View getView(int position, View convertView,
						ViewGroup parent) {
					TextView tv = new TextView(mContext);
					tv.setText(getItem(position).toString());
					tv.setTextSize(16);
					return tv;
				}

			};
//			mSpinnerWuLiao.setAdapter(adaptor);

			mSpinnerJuDian
					.setOnItemSelectedListener(new OnItemSelectedListener() {

						@Override
						public void onItemSelected(AdapterView<?> arg0,
								View arg1, int arg2, long arg3) {

						}

						@Override
						public void onNothingSelected(AdapterView<?> arg0) {

						}

					});
		}
	}
	/**
	 * 展示搜索结果
	 */
	private void showSearchList(){
		//总数量 
		mTextViewTotle.setText(searchResponse.searchResponseModel.temp.number);
		//库房 
		mTextViewKuFang.setText(searchResponse.searchResponseModel.temp.numberwid);
		//条记录
		mTextViewResult.setText(searchResponse.searchResponseModel.temp.count+"");
		//局站，区域
		mTextViewJuZhan.setText(searchResponse.searchResponseModel.temp.numberrid);
		//物料编码
		mTextViewWuliaoBianMa.setText(searchResponse.searchResponseModel.temp.numbersid);
		mListWuLiaoSearch.clear();
		mListWuLiaoSearch.addAll(searchResponse.searchResponseModel.wuLiaoList);
		searchAdapter.notifyDataSetChanged();
		//展示页数
		tv_page_info.setText(currentPageNum + " / "+(searchResponse.searchResponseModel.temp.count%10==0?searchResponse.searchResponseModel.temp.count/10:searchResponse.searchResponseModel.temp.count/10+1) );
	}
	private class SearchAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mListWuLiaoSearch.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return mListWuLiaoSearch.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Holder holder = null;
			WuLiao wuLiao = (WuLiao) getItem(position);
			if (null == convertView) {
				holder = new Holder();
				convertView = View.inflate(SearchActivity.this, R.layout.item_search,null);
				convertView.setTag(holder);
				holder.quyu = (TextView) convertView.findViewById(R.id.quyu);
				holder.judianmingcheng = (TextView) convertView.findViewById(R.id.judianmingcheng);
				holder.kufang = (TextView) convertView.findViewById(R.id.kufang);
				holder.wuliaobianma = (TextView) convertView.findViewById(R.id.wuliaobianma);
				holder.shuliang = (TextView) convertView.findViewById(R.id.shuliang);
				holder.wuliaomiaoshu = (TextView) convertView.findViewById(R.id.wuliaomiaoshu);
				holder.wuliaodetail = (ImageView) convertView.findViewById(R.id.wuliaodetail);
				holder.wuliaodetail.setOnClickListener(wuLiaoDetailListener);
			}else{
				holder = (Holder) convertView.getTag();
			}
			holder.quyu.setText(getQuYuNameByRid(wuLiao.warehouse.rid));
			holder.judianmingcheng.setText(wuLiao.warehouse.pointname);
			holder.kufang.setText(wuLiao.warehouse.name);
			holder.wuliaobianma.setText(wuLiao.sparetype.code);
			holder.shuliang.setText(wuLiao.number);
			holder.wuliaomiaoshu.setText(wuLiao.sparetype.descrption);
			holder.wuliaodetail.setTag(position);
			return convertView;
		}
		/**
		 * 持久缓存
		 * @author zhangshuai
		 *
		 */
		private class  Holder{
			/**
			 * 区域
			 */
			public TextView quyu;
			/**
			 * 局点名称
			 */
			public TextView judianmingcheng;
			/**
			 * 库房
			 */
			public TextView kufang;
			/**
			 * 物料编码
			 */
			public TextView wuliaobianma;
			/**
			 * 物料描述
			 */
			public TextView shuliang;
			/**
			 * 区域
			 */
			public TextView wuliaomiaoshu;
			/**
			 * 图片
			 */
			public ImageView wuliaodetail;
		}
	}
	/**
	 * 安全的获取 Spinner的值
	 * @param spinner
	 * @return
	 */
	private String getSpinnerString(Spinner spinner){
		String value = "";
		if(spinner!=null && spinner.getSelectedItem()!=null){
			value = spinner.getSelectedItem().toString();
		}
		return value;
	}
	/**
	 * 当搜索结果条目点击时候
	 * @author Administrator
	 *
	 */
	private class SearchListItemClickListener implements OnItemClickListener{
		private WuLiao wuLiao;
		private Intent  intent;
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {

		}
	}
	/**
	 * 跳转入详细界面
	 */
	private void jumpToDetail(WuLiao wuLiao){
		Intent  intent;
		intent = new Intent();
		intent.setClass(SearchActivity.this, SearchDetailActivity.class);
		intent.putExtra(SearchDetailActivity.wuliaoKey, wuLiao);
		startActivity(intent);
	}
	/**
	 * 放大镜点击
	 * @author Administrator
	 *
	 */
	private class WuLiaoDetailListener  implements OnClickListener{
		private WuLiao wuLiao;
		@Override
		public void onClick(View v) {
			int position = (Integer) v.getTag();
			wuLiao = (WuLiao) searchAdapter.getItem(position);
			jumpToDetail(wuLiao);
		}
	}
	/**
	 * 根据区域id获取区域名称
	 * @param rId 区域i id 
	 * @return 区域名称
	 */
	public String getQuYuNameByRid(String rId){
		String name = null;
		if(mListQuYu != null || !TextUtils.isEmpty(rId)){
			for(QuYu quYu : mListQuYu){
				if(quYu != null && rId.equals(quYu.id)){
					name = quYu.name;
					break;
				}
			}
		}
		return name;
	}
}
